<template>
    <el-table :data="data" border stripe max-height="500">
        <el-table-column v-for="(item,index) in arr" :prop="item.prop" :key="index" :label="item.label"  min-width="200">

        </el-table-column>
    </el-table>
</template>

<script>
    export default {
        data() {
            return {
                data: [{
                    lineNo: 111,
                    datas: [{
                        name: 'xx'
                    }, {
                        name: 'dd'
                    }]
                }, {
                    lineNo: 222,
                    datas: [{
                        name: 'cc'
                    }]
                }, {
                    lineNo: 333,
                    datas: [{
                        name: 'qq'
                    }, {
                        name: 'ww'
                    }, {
                        name: 'ee'
                    }]
                }],
                arr: []
            }
        },
        mounted() {
            this.loadData()
        },
        methods: {
            loadData() {
                let data = this.data
                let arr = []
                for (let i = 0; i < data.length; i++) {
                    let el = data[i];
                    for (var tmp in el) {
                        if (tmp === 'datas' && el[tmp].length > 0) {
                            for (let j = 0; j < el[tmp].length; j++) {
                                let et = el[tmp][j];
                                for (var t in et) {
                                    let key = t + [j+1]
                                    el[key] = et[t]
                                    // data[i]['label']='机械'+j
                                    // console.log(et);
                                }
                            }
                        }
                    }
                }
                let sort = []
                for (let i = 0; i < data.length; i++) {
                    delete data[i].datas
                    sort.push(data[i])
                }
                let num = sort.sort((a, b) => Object.keys(b).length - Object.keys(a).length)[0]
                for (var tmp in num) {
                    let label = ''
                    if (tmp === 'lineNo') {
                        label = "专运线"
                    } else if (tmp.indexOf('name') > -1) {
                        label = '机械' + tmp.split('name')[1]
                    }
                    arr.push({
                        prop: tmp,
                        label: label
                    })
                    // console.log(tmp);
                }
                this.arr = arr
                this.data = data
                console.log(arr);
                console.log(data);
            }
        }
    }

</script>
